//
//  ZCRaisePayVC.m
//  zctx
//
//  Created by 郭亚京 on 15/10/12.
//  Copyright © 2015年 sanliang. All rights reserved.
//

#import "ZCRaisePayVC.h"
#import "ZCRaisePayCell.h"
#import "WXApi.h"
#import "ZCPayshareViewController.h"
#import "ZCRaiseCell.h"
#import "ZCInvolvedDetailsVC.h"

#import "ZCRaisePayMoneyCell.h"
#import "ZCredpacketsVC.h"

#import "ZCRedpackModelContent.h"


@interface ZCRaisePayVC ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate>

@property (nonatomic,strong)NSString *payType;
@property (nonatomic,strong)ZCRaisePayView *payView;
@property (nonatomic,strong)UILabel *moneyLable;
@property (nonatomic,strong)UITextField *textfield;
@property (nonatomic,strong)NSMutableArray *dataArray;


@property BOOL isok;  //金额是否满足领头10，跟投1

@property (nonatomic,assign)NSInteger monyOnce;  //初始金额
@property (nonatomic,assign)NSInteger moneyBegin;  //投金额
@property (nonatomic,strong)NSString *moneyStr;  //支付金额
@property (nonatomic,strong)NSString *redmoney; //红包金额
@property (nonatomic,strong)NSString *redid; //红包id
@end

@implementation ZCRaisePayVC


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"ZCRaisePayVC"];
    [MTA trackPageViewBegin:@"ZCRaisePayVC"];
    self.tabBarController.hidesBottomBarWhenPushed = YES;
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"ZCRaisePayVC"];
    [MTA trackPageViewEnd:@"ZCRaisePayVC"];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    self.view.shiftHeightAsDodgeViewForMLInputDodger = 50.0f;
    [self.view registerAsDodgeViewForMLInputDodger];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.payType = @"0";
    [self.navigationItem setTitle:@"支付"];
    self.selectIndex = 0;
    self.automaticallyAdjustsScrollViewInsets =NO;
    self.edgesForExtendedLayout = UIRectEdgeNone;
   
    [self requestRedData];//请求红包数据
    
    [self initnavegation]; //导航栏
    [self initTableViewHead]; //tableView head
    [self initFootView];
    self.tableView.backgroundColor = [UIColor colorWithHexString:@"#fafcfb"];
    self.tableView.separatorColor = RGB(236, 237, 238);
    self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
    [self.tableView registerNib:[UINib nibWithNibName:@"ZCRaisePayCell" bundle:nil] forCellReuseIdentifier:@"playcell"];
    
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)])
    {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])
    {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
    [self weichatResult];//微信支付结果通知
}

-(void)requestRedData{
    [NetworkManager requestGetMyRedpackWithmid:UserModel.mid password:UserModel.password type:@"0" pagecount:@"0" rp_id:@"0" success:^(NSDictionary *dictResponse) {
        
        if ([[dictResponse objectForKey:@"content"] isKindOfClass:[NSArray class]]){
            NSArray *sarray = (NSArray *)[dictResponse objectForKey:@"content"];
            if (sarray.count>0) {
                
                for (int i=0;i<sarray.count; i++) {
                    ZCRedpackModelContent *model = [ZCRedpackModelContent modelObjectWithDictionary:sarray[i]];
                    [self.dataArray addObject:model];
                }
                [self.tableView reloadData];
            }else{
                
            }
        }
    } failure:^(NSError *error) {
        
    }];
}
#pragma mark 导航栏
-(void)initnavegation{
    
    UIButton * leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame = CGRectMake(0, 0, 19, 36);
    [leftButton setImage:[UIImage imageNamed:@"navigation_back"] forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(backButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * barButtonItem_leftNavBar = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = barButtonItem_leftNavBar;
}

-(void)backButtonPressed{
    ProgressDismiss;
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)initTableViewHead{
    if ([self.markStr isEqualToString:@"1"]) {
        self.moneyBegin = 10;
        self.monyOnce = 10;
    }else{
        self.moneyBegin = 1;
        self.monyOnce  =1;
    }
    UIView * headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 180-5)];
    headView.backgroundColor = [UIColor whiteColor];
    
    
    UILabel *titlelable = [[UILabel alloc]init];
    [headView addSubview:titlelable];
    [titlelable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(headView.left).with.offset(19);
        make.right.equalTo(headView.right).with.offset(-19);
        make.top.equalTo(headView.top).with.offset(10);
        make.height.mas_equalTo(25);
    }];
    titlelable.textColor = [UIColor colorWithHexString:@"#000000"];
    titlelable.text = self.pjname;
    titlelable.font = [UIFont systemFontOfSize:16];
    
    UILabel *namelable = [[UILabel alloc]init];
    [headView addSubview:namelable];
    [namelable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(headView.left).with.offset(19);
        make.right.equalTo(headView.right).with.offset(-19);
        make.top.equalTo(titlelable.bottom).with.offset(0);
        make.height.mas_equalTo(25);
    }];
    namelable.text =[NSString stringWithFormat:@"发起人:%@",self.pjusername];
    namelable.textColor = [UIColor colorWithHexString:@"#8a8a8a"];
    namelable.font = [UIFont systemFontOfSize:13];
    
    
    UIView *lineOneView = [[UIView alloc]init];
    [headView addSubview:lineOneView];
    [lineOneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(headView.right).with.offset(0);
        make.left.equalTo(headView.left).with.offset(0);
        make.height.mas_equalTo(@5);
        make.top.equalTo(namelable.bottom).with.offset(10);
    }];
    lineOneView.layer.borderWidth = 0.5;
    lineOneView.layer.borderColor = RGB(236, 237, 238).CGColor;
    lineOneView.backgroundColor = [UIColor colorWithHexString:@"#fafcfb"];
    
    
    UILabel *palylable = [[UILabel alloc]init];
    [headView addSubview:palylable];
    [palylable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(headView.left).with.offset(19);
        make.height.mas_equalTo(@40);
        make.width.mas_equalTo(50);
        make.top.equalTo(lineOneView.bottom).with.offset(10);
    }];
    palylable.textColor = [UIColor colorWithHexString:@"#000000"];
    palylable.text = @"支持:";
    palylable.font = [UIFont systemFontOfSize:16];

    self.payView = [[ZCRaisePayView alloc]init];
    
    if ([self.markStr isEqualToString:@"1"]) {
        self.payView.titleButtonArray = [NSArray arrayWithObjects:@"10元",@"20元",@"50元",@"100元", nil];
    }else{
        self.payView.titleButtonArray = [NSArray arrayWithObjects:@"1元",@"10元",@"20元",@"50元",nil];
    }
    [headView addSubview:self.payView];
    
    if (IS_IPHONE_4_OR_LESS ||IS_IPHONE_5) {
        [self.payView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(headView.right).with.offset(0);
            make.left.equalTo(headView.left).with.offset(75);
            make.height.mas_equalTo(@40);
            make.top.equalTo(lineOneView.bottom).with.offset(10);
        }];
    }else{
        [self.payView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(headView.right).with.offset(0);
            make.left.equalTo(headView.left).with.offset(100);
            make.height.mas_equalTo(@40);
            make.top.equalTo(lineOneView.bottom).with.offset(10);
        }];
    }
    __block ZCRaisePayVC *weekself = self;
    self.payView.moneyButtonClik = ^(NSInteger tag,NSString *title){
        [weekself.textfield resignFirstResponder];
        weekself.textfield.text = @"";
        NSLog(@"tag = %ld,title = %ld",(long)tag,[title integerValue]);
        weekself.moneyBegin = [title integerValue];
        NSIndexPath *indexs = [NSIndexPath indexPathForRow:1 inSection:0];
        [weekself.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexs] withRowAnimation:UITableViewRowAnimationNone];
    };
    self.textfield = [[UITextField alloc]init];
    [headView addSubview:self.textfield];
    [self.textfield mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.payView.left).with.offset(0);
        make.width.mas_equalTo(120);
        make.height.mas_equalTo(@30);
        make.top.equalTo(self.payView.bottom).with.offset(5);
    }];
    self.textfield.delegate = self;
    self.textfield.borderStyle = UITextBorderStyleNone;
    [self.textfield setBackground:[UIImage imageNamed:@"pay_text"]];
    self.textfield.font = [UIFont systemFontOfSize:15];
    self.textfield.placeholder = @"自定义金额";
    self.textfield.keyboardType = UIKeyboardTypeNumberPad;
    self.textfield.textColor = [UIColor colorWithHexString:@"#8a8a8a"];
    [self.textfield addTarget:self action:@selector(textFieldChanged:) forControlEvents:UIControlEventEditingChanged];
    
    UILabel *tixinglable = [[UILabel alloc]init];
    [headView addSubview:tixinglable];
    [tixinglable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.textfield.right).with.offset(10);
        make.centerY.equalTo(self.textfield.centerY).with.offset(0);
        make.height.mas_equalTo(@(21));
        make.width.mas_equalTo(30);
    }];
    tixinglable.textAlignment =NSTextAlignmentLeft;
    tixinglable.font = [UIFont systemFontOfSize:15];
    tixinglable.textColor = [UIColor colorWithHexString:@"#666666"];
    tixinglable.text = @"元";
    
    
    
    
//    UIView *lineView = [[UIView alloc]init];
//    [headView addSubview:lineView];
//    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(headView.right).with.offset(0);
//        make.left.equalTo(self.textfield.left).with.offset(0);
//        make.height.mas_equalTo(@1);
//        make.top.equalTo(self.textfield.bottom).with.offset(15);
//    }];
//    lineView.backgroundColor = [UIColor groupTableViewBackgroundColor];
//    
//    UILabel *linelable = [[UILabel alloc]init];
//    [headView addSubview:linelable];
//    [linelable mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(headView.left).with.offset(29);
//        make.top.equalTo(lineView.bottom).with.offset(0);
//        make.bottom.equalTo(headView.bottom).with.offset(0);
//    }];
//    linelable.text = @"支付金额：";
//    linelable.font = [UIFont systemFontOfSize:16];
//    linelable.textColor = [UIColor colorWithHexString:@"#525252"];
//    
//   self.moneyLable = [[UILabel alloc]init];
//    [headView addSubview:self.moneyLable];
//    [self.moneyLable mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(linelable.right).with.offset(0);
//        make.centerY.equalTo(linelable.centerY).with.offset(0);
//        make.width.mas_equalTo(150);
//        make.height.equalTo(linelable.height).with.offset(0);
//    }];
//    if ([self.markStr isEqualToString:@"1"]) {
//        self.moneyLable.text = @"￥ 10元";
//    }else{
//        self.moneyLable.text = @"￥ 1元";
//    }
//    self.moneyLable.font = [UIFont systemFontOfSize:15];
//    self.moneyLable.textColor = [UIColor redColor];
    self.tableView.tableHeaderView = headView;
    
}

-(void)initFootView{
    
    UIView * footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100)];
    UIButton *okButton = [UIButton new];
    [footView addSubview:okButton];
    okButton.layer.cornerRadius = 5.0f;
    okButton.layer.masksToBounds = YES;
    [okButton setTitle:@"确认支付" forState:UIControlStateNormal];
//    okButton.backgroundColor = [UIColor colorWithHexString:@"#03Ab9e"];
    
    [okButton setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:@"#03ab9e"]] forState:UIControlStateNormal];
    [okButton setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:@"#03ab9e" andAlpha:0.6]] forState:UIControlStateHighlighted];
    [okButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(footView.top).with.offset(40);
        make.left.equalTo(footView).with.offset(19);
        make.right.equalTo(footView).with.offset(-19);
        make.height.mas_equalTo(@40);
    }];
    okButton.userInteractionEnabled = YES;
    [okButton addTarget:self action:@selector(senderOKButtonClick) forControlEvents:UIControlEventTouchUpInside];
    self.tableView.tableFooterView = footView;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 3;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==0) {
        if (self.dataArray.count>0) {
            static NSString *cellid = @"playredcells";
            ZCRaisePayMoneyCell *cell = [[ZCRaisePayMoneyCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid cellType:ZCRaisePayMoneyCellTypeRed andRed:NO];
            cell.titleLable.text = @"红包";
            if (self.redmoney) {
                cell.redLable.text = [NSString stringWithFormat:@"%d元红包",[self.redmoney intValue]];
            }else{
               
                ZCRedpackModelContent *model = (ZCRedpackModelContent *)self.dataArray[0];
                NSLog(@"modelss = %@",model.cash);
                self.redmoney = model.cash;
                self.redid = model.rpId;
                cell.redLable.text = [NSString stringWithFormat:@"%d元红包",[model.cash intValue]];
                if (self.moneyBegin < [model.cash integerValue]) {
                    [self.payView selectButtonAllNo];
                    self.textfield.text = [NSString stringWithFormat:@"%d",[model.cash intValue]];
                }
            }
            return cell;
        }else{
            static NSString *cellid = @"playredcell";
            ZCRaisePayMoneyCell *cell = [[ZCRaisePayMoneyCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid cellType:ZCRaisePayMoneyCellTypeNoRed andRed:NO];
            cell.titleLable.text = @"红包";
            return cell;
        }
    }else if (indexPath.row ==1){
        static NSString *cellid = @"playmoneycell";
        ZCRaisePayMoneyCell *cell = [[ZCRaisePayMoneyCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid cellType:ZCRaisePayMoneyCellTypeMoney andRed:NO];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.titleLable.text = @"支付金额";
        NSInteger money;
        NSInteger redmoney = [self.redmoney integerValue];
       
        if ([self.textfield.text integerValue]>0) {
            if ([self.textfield.text integerValue]>=redmoney) {
                money = [self.textfield.text integerValue] - redmoney;
            }else{
                money = 0;
            }
            if (([self.textfield.text integerValue] + redmoney) >= self.monyOnce) {
                self.isok = YES;
            }else{
                self.isok = NO;
            }
        }else{
            self.isok = YES;
            if (self.moneyBegin>=redmoney) {
                money = self.moneyBegin - redmoney;
            }else{
                money = 0;
            }
        }
//         NSLog(@"textFiled.text =%ld , redmoney = %ld , money = %ld",self.moneyBegin,redmoney,self.moneyBegin);
        cell.moneyLable.text =[NSString stringWithFormat:@"￥%ld元",money];
        return cell;
    }else{
        static NSString *cellid = @"playcell";
        ZCRaisePayCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.indexpath = indexPath;
        NSIndexPath *firstPath = [NSIndexPath indexPathForRow:2 inSection:0];
        [self.tableView selectRowAtIndexPath:firstPath animated:YES scrollPosition:UITableViewScrollPositionNone];
        return cell;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row<2) {
        return 44;
    }else{
        return 71;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self.textfield resignFirstResponder];
//    self.payType = [NSString stringWithFormat:@"%lu", (long)indexPath.row];
    
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row==0) {
        ZCredpacketsVC *redvc = [[ZCredpacketsVC alloc]init];
        redvc.ispay = 1;
        redvc.hidesBottomBarWhenPushed =YES;
        redvc.rp_id = self.redid;
        redvc.returnRedblock = ^(NSString *money,NSString *rpid){
            NSLog(@"money =%@  rpid = %@",money,rpid);
            self.redmoney = money;
            self.redid = rpid;
            if (self.moneyBegin<=[money integerValue]) {
                [self.payView selectButtonAllNo];
                self.textfield.text = [NSString stringWithFormat:@"%ld",[money integerValue]];
            }
            NSIndexPath *index = [NSIndexPath indexPathForRow:0 inSection:0];
            NSIndexPath *indexs = [NSIndexPath indexPathForRow:1 inSection:0];
            [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:index,indexs, nil] withRowAnimation:UITableViewRowAnimationNone];
        };
        [self.navigationController pushViewController:redvc animated:YES];
    }

    NSLog(@"indexpath.row = %ld",(long)indexPath.row);
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)])
    {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)])
    {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

#pragma mark 确认支付
-(void)senderOKButtonClick{
   
    NSLog(@"点击了支付--money = %ld , isok = %d",self.moneyBegin,self.isok);
    
    [self.textfield resignFirstResponder];
    if ([WXApi isWXAppInstalled]) {
        
        ZCRaisePayMoneyCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
        NSScanner *scanner = [NSScanner scannerWithString:cell.moneyLable.text];
        [scanner scanUpToCharactersFromSet:[NSCharacterSet decimalDigitCharacterSet] intoString:nil];
        int number = 0;
        [scanner scanInt:&number];
        _moneyStr = [NSString stringWithFormat:@"%d",number*100];
        
        if ([self.markStr isEqualToString:@"1"]) {
            if (self.isok ==NO) {
                [[[iToast makeText:@"领投众测项目10元起"]setGravity:iToastGravityBottom] show];
                return;
            }
        }
        else
        {
            if (self.isok ==NO) {
                [[[iToast makeText:@"跟投众测项目1元起"]setGravity:iToastGravityBottom] show];
                return;
            }
        }
//        if ([self.payType isEqualToString:@"0"]) {
            [self wxButtonClick];
//        } else if ([self.payType isEqualToString:@"1"]) {
//            [self aliPayButtonClick];
//        }
    }else{
        //未安装微信
        [[[iToast makeText:@"亲,请先安装微信吧~"]setGravity:iToastGravityBottom] show];
    }
}

#pragma mark 微信支付
- (void)wxButtonClick{
    
    NSString *rp = @"0";
    if (self.redid) {
        rp = self.redid;
    }
    NSLog(@"%@,%@,%@,%@,%@",UserModel.mid,UserModel.password,@"1",self.pid,_moneyStr);
    [SVProgressHUD showWithStatus:@"支付中..."];
    [NetworkManager requestFoundingPayitWithMid:UserModel.mid password:UserModel.password type:@"1" fdid:self.pid donate:_moneyStr rp_id:rp success:^(NSDictionary *dictResponse) {
        ProgressDismiss;
        NSString *msg = [NSString stringWithFormat:@"%@",[dictResponse objectForKey:@"msg"]];
        if ([msg isEqualToString:@"noneedpay"]) {//应该支付0元
            [self paysharesuccessUI];
        }
        if ([[dictResponse objectForKey:@"content"] isKindOfClass:[NSDictionary class]]) {
            NSDictionary *dict =(NSDictionary *)[dictResponse objectForKey:@"content"];
            PayReq *req = [[PayReq alloc] init];
            req.prepayId = [NSString stringWithFormat:@"%@",[dict objectForKey:@"prepayId"]];
            req.partnerId = [NSString stringWithFormat:@"%@",[dict objectForKey:@"partnerId"]];
            req.package = [NSString stringWithFormat:@"%@",[dict objectForKey:@"package"]];
            req.timeStamp = [[NSString stringWithFormat:@"%@",[dict objectForKey:@"timeStamp"]]intValue];
            req.sign = [NSString stringWithFormat:@"%@",[dict objectForKey:@"sign"]];
            req.nonceStr = [NSString stringWithFormat:@"%@",[dict objectForKey:@"nonceStr"]];
            [WXApi sendReq:req];
        }
    } failure:^(NSError *error) {
    }];

}

#pragma mark 支付宝支付
- (void)aliPayButtonClick {
    
//    [self paysharesuccessUI];
    
//    [alipayManager payOrderWithTitle:self.model.name price:self.model.final_price callback:^(NSDictionary *resultDic) {
//        [SVProgressHUD dismiss];
//        
//        NSString *result = @"";
//        if ([[resultDic objectForKey:@"resultStatus"] intValue] == 9000 && [[resultDic objectForKey:@"success"] isEqualToString:@"true"]) {
//            result = @"支付成功";
//        } else {
//            result = @"支付失败";
//        }
//        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:result message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
//        alertView.tag = 2;
//        [alertView show];
//    }];
}

-(void)weichatResult{
    
    NSLog(@"root  == ");
   __block __weak id observer =[[NSNotificationCenter defaultCenter] addObserverForName:@"WXPayResult" object:nil queue:NSOperationQueuePriorityNormal usingBlock:^(NSNotification *note) {
        NSLog(@"payCode = %@", [note.userInfo objectForKey:@"payCode"]);
        
        NSString *code = [note.userInfo objectForKey:@"payCode"];
        
        [SVProgressHUD dismiss];
        
        NSString *result = @"";
        if ([code isEqualToString:@"0"]) {
              [[[iToast makeText:@"支付成功"]setGravity:iToastGravityCenter] show];
            [self paysharesuccessUI];
        } else if ([code isEqualToString:@"-2"]) {
            result = @"支付取消";
            [self alertViewShow:result];
        } else {
            result = @"支付失败";
            [self alertViewShow:result];
        }
       [[NSNotificationCenter defaultCenter]
        removeObserver:observer
        name:@"WXPayResult"
        object:nil];
    }];
}

-(void)alertViewShow:(NSString *)result{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:result message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
    alertView.tag = 1;
    [alertView show];
}
#pragma mark 支付成功界面
-(void)paysharesuccessUI{
    
    NSLog(@"支付成功了 ----- - - - ");
    
    ZCInvolvedDetailsVC *zcvc = [[ZCInvolvedDetailsVC alloc]init];
    zcvc.pid = self.pid;
    if ([self.markStr isEqualToString:@"1"]) {
        zcvc.backState = 1;   //发起返回跳转
    }else{
        zcvc.backState = 2;   //跟投返回跳转
    }
    
    NSNotification *notification =[NSNotification notificationWithName:@"payMoney" object:nil userInfo:nil];
    [[NSNotificationCenter defaultCenter]postNotification:notification];
    
    zcvc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:zcvc animated:YES];
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}
#pragma mark textfield.text 发生改变
-(void)textFieldChanged:(UITextField *)textFiled{
   [self.payView selectButtonAllNo];
    self.moneyBegin = [textFiled.text integerValue];
    NSIndexPath *indexs = [NSIndexPath indexPathForRow:1 inSection:0];
    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexs] withRowAnimation:UITableViewRowAnimationNone];
}

#pragma mark 开始编辑触发
- (void)textFieldDidBeginEditing:(UITextField *)textField{
    NSLog(@"编辑");
}

-(void)resignfirst{
    [self.textfield resignFirstResponder];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [NSMutableArray arrayWithCapacity:0];
    }
    return _dataArray;
}


@end
